package com.matrix.demo;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Rect;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;

/**
 * Created by lgs on 2018/5/4.
 */

public class CustomView extends View {

    private Paint mRectPaint;//画矩形的画笔
    private Rect rect = new Rect(0, 0, 200, 200);

    {
        mRectPaint = new Paint();
        mRectPaint.setAntiAlias(true);
        mRectPaint.setColor(Color.GREEN);
    }

    public CustomView(Context context) {
        super(context);
    }

    public CustomView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    public CustomView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        canvas.drawRect(rect, mRectPaint);
        postInvalidate();
    }

    @Override
    public boolean onTouchEvent(MotionEvent event) {
        super.onTouchEvent(event);
        performClick();
        switch (event.getAction()) {
            case MotionEvent.ACTION_DOWN:
                Log.i("down", "Action Down");
            case MotionEvent.ACTION_MOVE:
                ViewPortHandler.zoomIn(30f,60f);
                break;
        }
        return true;
    }
}
